package com.xy.biz.xd.domain.converter;

import java.util.Collection;
import java.util.List;

import com.xy.biz.xd.domain.bo.DocumentFlowNewAndModifyBO;
import com.xy.biz.xd.domain.po.DocumentFlowNewAndModifyPO;
import com.xy.biz.xd.domain.query.DocumentFlowNewAndModifyQuery;
import com.xy.biz.xd.domain.req.*;
import com.xy.biz.xd.domain.resp.GetDocumentFlowNewAndModifyResponse;
import com.xy.biz.xd.domain.resp.GetDocumentFlowNewResponse;
import com.xy.biz.xd.domain.resp.ListDocumentFlowNewAndModifyResponse;
import com.xy.tool.util.BeanUtilsEx;

/**
 *
 *
 * @author wcs
 * @date 2021-2-26
 */
public class DocumentFlowNewAndModifyConverter {

    public static DocumentFlowNewAndModifyPO toPO(DocumentFlowNewAndModifyBO source) {
        return BeanUtilsEx.copyProperties(source, () -> new DocumentFlowNewAndModifyPO(), true);
    }

    public static List<DocumentFlowNewAndModifyPO> toPO(Collection<DocumentFlowNewAndModifyBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new DocumentFlowNewAndModifyPO(), true);
    }

    public static DocumentFlowNewAndModifyBO fromPO(DocumentFlowNewAndModifyPO source) {
        return BeanUtilsEx.copyProperties(source, () -> new DocumentFlowNewAndModifyBO());
    }

    public static List<DocumentFlowNewAndModifyBO> fromPO(Collection<DocumentFlowNewAndModifyPO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new DocumentFlowNewAndModifyBO());
    }

    public static DocumentFlowNewAndModifyBO toBO(SaveDocumentFlowNewRequest source) {
        return BeanUtilsEx.copyProperties(source, () -> new DocumentFlowNewAndModifyBO(), true);
    }

    public static List<DocumentFlowNewAndModifyBO> toBO(Collection<SaveDocumentFlowNewRequest> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new DocumentFlowNewAndModifyBO(), true);
    }

    public static List<DocumentFlowNewAndModifyBO> toBOList(ApplyDocumentFlowNewAndModifyRequest source) {
        if (source instanceof ApplyDocumentFlowNewRequest) {
            return BeanUtilsEx.copyPropertiesForNewList(((ApplyDocumentFlowNewRequest) source).getDocumentFlowInfoList(), DocumentFlowNewAndModifyBO::new, (src, tar) -> {
                tar.setDocumentManagerUserId(source.getDocumentManagerUserId());
                //tar.setDocumentManagerUserIdList(source.getDocumentManagerUserIdList());
                tar.setReason(source.getReason());
                tar.setUrgent(source.getUrgent());
                tar.setBatchType(source.getBatchType());
            });
        } else /*if (source instanceof ApplyDocumentFlowModifyRequest) */ {
            return BeanUtilsEx.copyPropertiesForNewList(((ApplyDocumentFlowModifyRequest) source).getDocumentFlowInfoList(), DocumentFlowNewAndModifyBO::new, (src, tar) -> {
                tar.setDocumentManagerUserId(source.getDocumentManagerUserId());
                //tar.setDocumentManagerUserIdList(source.getDocumentManagerUserIdList());
                tar.setReason(source.getReason());
                tar.setUrgent(source.getUrgent());
                tar.setBatchType(source.getBatchType());
            });
        }
    }

    public static DocumentFlowNewAndModifyBO toBO(ApplyDocumentFlowNewRequest source) {
        return BeanUtilsEx.copyProperties(source, () -> new DocumentFlowNewAndModifyBO(), true);
    }

    public static DocumentFlowNewAndModifyBO toBO(ApplyDocumentFlowModifyRequest source) {
        return BeanUtilsEx.copyProperties(source, () -> new DocumentFlowNewAndModifyBO(), true);
    }

    public static DocumentFlowNewAndModifyQuery toQuery(ListDocumentFlowNewAndModifyRequest source) {
        if (null == source) {
            return null;
        }
        DocumentFlowNewAndModifyQuery target = new DocumentFlowNewAndModifyQuery(source.getPageIndex(), source.getPageSize());
        BeanUtilsEx.copyProperties(source, target);
        return target;
    }

    public static GetDocumentFlowNewResponse toResponse(DocumentFlowNewAndModifyBO source) {
        return BeanUtilsEx.copyProperties(source, () -> new GetDocumentFlowNewResponse());
    }

    public static List<GetDocumentFlowNewResponse> toResponse(Collection<DocumentFlowNewAndModifyBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new GetDocumentFlowNewResponse());
    }

    public static List<ListDocumentFlowNewAndModifyResponse.DocumentFlowInfo> toResponseList(Collection<DocumentFlowNewAndModifyBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, () -> new ListDocumentFlowNewAndModifyResponse.DocumentFlowInfo());
    }

    public static ListDocumentFlowNewAndModifyResponse toResponseList(DocumentFlowNewAndModifyBO source) {
        return BeanUtilsEx.copyProperties(source, () -> new ListDocumentFlowNewAndModifyResponse());
    }

    public static GetDocumentFlowNewAndModifyResponse toResponse2(DocumentFlowNewAndModifyBO source) {
        return BeanUtilsEx.copyProperties(source, () -> new GetDocumentFlowNewAndModifyResponse());
    }

    public static List<GetDocumentFlowNewAndModifyResponse> toResponse2(Collection<DocumentFlowNewAndModifyBO> source) {
        return BeanUtilsEx.copyPropertiesForNewList(source, GetDocumentFlowNewAndModifyResponse::new);
    }

}
